<?php
mysql_connect("127.0.0.1","root","sd2013");
mysql_select_db("mathRomp");

//Get array of current games
$q = mysql_query("SELECT gus.userId, gus.gameId, u.username FROM `Games-Users` AS gus JOIN Users AS u ON gus.gameId = ANY (SELECT g.gameId FROM `Games-Users` AS gu JOIN Game AS g ON g.gameId = gu.gameId AND g.turn=".$_REQUEST['userId']." AND gu.userId = ".$_REQUEST['userId'].") AND gus.userId != ".$_REQUEST['userId']." AND gus.userId = u.userId");

while($g=mysql_fetch_assoc($q)){
  $output[]=$g;
}
print(json_encode($output));

?>